var tjmove = 0;
var cd = 0;
$("#youjiantou").click(function() {
	if (tjmove > (-920)&&cd==0) {
		var rc = setInterval(function() {
			$("#tuijian>div").css("margin-left", tjmove);
			if (cd == 5) {
				clearInterval(rc);
				cd=0;
			} else {
				tjmove -= 46;
				cd++;
			}
		}, 100)
	}
});
$("#zuojiantou").click(function() {
	if (tjmove < 0&&cd==0) {
		var lc = setInterval(function() {
			$("#tuijian>div").css("margin-left", tjmove);
			if (cd == 5) {
				clearInterval(lc);
				cd=0;
			}else{
				tjmove += 46;
				cd++;
			}
		}, 100)
	}
});
window.onload = function() {
				var APP_ID = 'eG22PNfwqck3fDTem41ACiNU-gzGzoHsz';
				var APP_KEY = 'Y8VoXz0cIzsJVbpctUAJXAAh';
				AV.init({
					appId: APP_ID,
					appKey: APP_KEY
				});
				pddenglu();
				var currentUser = AV.User.current();
				updateProduct();
			}
		function pddenglu() {
	currentUser = AV.User.current();
	href = "denglu.html?RetUrl=" + getPageUrl() + "&" + geturl();
	$(".top_a ul li").eq(1).html("<a href=" + href + ">登录</a>")
	if(currentUser) {
		$(".top_a ul li").eq(0).html("欢迎【" + currentUser.attributes.username + "】|");
		$(".top_a ul li").eq(1).html("<a>退出登录</a>");
		$(".top_a ul li").eq(1).bind("click", function() {
			localStorage.clear();
			location.href = location.href;
		})
	}
}

function getPageUrl() {
	var index = location.pathname.lastIndexOf("/") + 1;
	var i = location.pathname.substr(index);
	//			console.log(i)
	return escape(i)
}

function geturl() {
	var u = location.search;
	u = u.substring(1, (u.length))
	console.log(u);
	return u;
}
			function updateProduct() {
				// LeanCloud - 查询
				// https://leancloud.cn/docs/leanstorage_guide-js.html#查询
				var query = new AV.Query('Canvas');
//				query.include('owner');
//				query.include('image');
				query.descending('createdAt');
				query.find().then(function(products) {
					for(var i=0;i<8;i++){
						var divtj='<div class="tj"><a href="ComDet.html?biao=Canvas&id='+products[i].attributes.inid+'">';
						divtj+='<img src="' + products[i].attributes.image[0] + '">';
						divtj+='<span>'+products[i].attributes.title+'</span>';
						divtj+='</a></div>';
						$("#tuijian_div").append(divtj);
					}
//					$('#addimg").html(products[0].attributes.title);
					// 查询到商品后，在前端展示到相应的位置中

				}).catch(function(error) {
					alert(JSON.stringify(error));
				});

			}
